﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ModelLibrary

{
    /// <summary>
    /// 主菜单按钮
    /// </summary>
    public class DrawingMainMenuBtn
    {
        //public DrawingMainMenuBtn()
        //{
        //    RePaint();
        //}
        //public DrawingMainMenuBtn(Control ctrl)
        //{
        //    control = ctrl;
        //    RePaint();
        //}
        //public DrawingMainMenuBtn RePaint()
        //{
        //    return new DrawingMainMenuBtn(control, size, BrushBackground, BrushFont, font, Text, point);
        //}
        public DrawingMainMenuBtn(Control ctrl, Size sz, Brush brushBg, Brush brushFt, Font ft, string text, Point pt)
        {
            control = ctrl;
            size = sz;
            BrushBackground = brushBg;
            BrushFont = brushFt;
            font = ft;
            Text = text;
            point = pt;

            using (Graphics g = ctrl.CreateGraphics())
            {
                using (Pen p = new Pen(brushBg))
                {

                    Rectangle rct = new Rectangle(pt, sz);
                    g.FillRectangle(brushBg, rct);
                    Point fontpt = new Point();
                    SizeF fontSize = g.MeasureString(text, ft);
                    if (sz.Width > (int)fontSize.Width)
                    {

                        fontpt.X = pt.X + (sz.Width - (int)fontSize.Width) / 2;
                    }
                    else
                        fontpt.X = 0;
                    fontpt.Y = pt.Y + (sz.Height - (int)fontSize.Height) / 2;
                    g.DrawString(text, ft, brushFt, fontpt);

                }
            }
        }

        public Control control { get { return _control; } set { _control = value; } }
        public Control _control = new Control();
        public Size size { get { return _size; } set { _size = value; } }
        public Size _size = new Size(80, 40);

        public Brush BrushBackground { get { return _BrushBackground; } set { _BrushBackground = value; } }
        public Brush _BrushBackground = Brushes.LightGray;


        public Brush BrushFont { get { return _BrushFont; } set { _BrushFont = value; } }
        public Brush _BrushFont = Brushes.Black;

        public string Text { get { return _Text; } set { _Text = value; } }
        public string _Text = "";

        public Font font { get { return _font; } set { _font = value; } }
        public Font _font = new Font("宋体", 12f);

        public Point point { get { return _point; } set { _point = value; } }
        public Point _point = new Point(0, 0);

    }
}
